package com.wanter.vote.service.impl;

import com.wanter.common.utils.ID.IDutils;
import com.wanter.users.entity.User;
import com.wanter.users.mapper.UserMapper;
import com.wanter.users.service.UserService;
import com.wanter.vote.entity.Vote;
import com.wanter.vote.mapper.VoteMapper;
import com.wanter.vote.service.VoteService;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 实现类
 * Created by er on 2017/5/19.
 */
@Service
public class VoteServiceImpl implements VoteService {
    private final Logger logger = Logger.getLogger(this.getClass());

    @Resource
    private VoteMapper voteMapper;
    @Resource
    private UserMapper userMapper;


    @Override
    public void insertVote(Vote vote) {
        if (StringUtils.isEmpty(vote)){
            if (logger.isInfoEnabled()){
                logger.info("插入信息失败,传入对象为空");
            }
            return;
        }
        if(StringUtils.isEmpty(vote.getVoteUser().getId())){
            logger.info("插入信息失败,缺少用户id信息");
            return;
        }
        vote.setId(IDutils.getUUID());
        vote.setVoteDate(new Date());
        voteMapper.insert(vote);

    }

    @Override
    public void deleteVote(String id) {
        if (!StringUtils.isEmpty(id)) {
            voteMapper.deleteByPrimaryKey(id);
            if (logger.isInfoEnabled()) {
                logger.info("删除投票信息成功" + id);
            }
        }
    }
}
